package softtech.apps.utility;

import softtech.apps.callblocker.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.method.ScrollingMovementMethod;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyDialog {
	
//	Context context;
	
	Dialog myDialog;
	
	EditText txtCheckCode;
	
	CheckBox cbxCheck;
	
	public MyDialog(Context ctx){
//		context=ctx;
	}
	
	
	/*
	 *  dialog 2 nut  + 1 edit text
	 * **/
	public MyDialog(Context context,String title,String message,String title_button1,String title_button2,final OnClickListener leftClickListener,final OnClickListener rightClickListener,String content_edittext){
		myDialog = new Dialog(context);
		
		DisplayMetrics displayMetrics = new DisplayMetrics();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut
        wm.getDefaultDisplay().getMetrics(displayMetrics);
        int screenHeight = displayMetrics.heightPixels;
        int screenWidht = displayMetrics.widthPixels;
		
        myDialog.setContentView(R.layout.dialog_3button_1edittext_1textbox);
        myDialog.setOwnerActivity((Activity) context);
        LinearLayout R_logout = (LinearLayout) myDialog.findViewById(R.id.r_dialog);
        FrameLayout.LayoutParams params_dialog;
        
        if (screenWidht > screenHeight) {
        	 params_dialog = new FrameLayout.LayoutParams(screenHeight*85/100,LayoutParams.WRAP_CONTENT);
		}
        else {
        	 params_dialog = new FrameLayout.LayoutParams(screenWidht*85/100,LayoutParams.WRAP_CONTENT);
		}
        
        params_dialog.gravity = Gravity.CENTER;
        R_logout.setLayoutParams(params_dialog);
        myDialog.setCancelable(false);
        
        myDialog.setTitle(title);
        
        
        TextView text = (TextView) myDialog.findViewById(R.id.TextView01);
        if (screenWidht > screenHeight) {
        	text.setHeight((screenWidht*30/100)*77/100);
		}
        else {
        	text.setHeight((screenHeight*30/100)*77/100);
		}
        text.setMovementMethod(ScrollingMovementMethod.getInstance());
        text.setVisibility(View.GONE);
        
        txtCheckCode=(EditText)myDialog.findViewById(R.id.txtCheckCode);
        txtCheckCode.setText(content_edittext);
        txtCheckCode.setBackgroundResource(R.drawable.text_login_border);
        
        Button cmdleft = (Button) myDialog.findViewById(R.id.cmdLeft);
        cmdleft.setText(title_button1);
        cmdleft.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
								
				if(txtCheckCode.getText().toString().trim().equals(""))
					return;
				if(leftClickListener!=null){
					leftClickListener.onClick(v);
				}
				
				myDialog.dismiss();
			}
		});
        
        Button cmdCenter = (Button) myDialog.findViewById(R.id.cmdCenter);
        cmdCenter.setVisibility(View.GONE);
        
        LinearLayout linear_center=(LinearLayout) myDialog.findViewById(R.id.linear_center);
        linear_center.setVisibility(View.GONE);
        
        Button cmdRight = (Button) myDialog.findViewById(R.id.cmdRight);
        cmdRight.setText(title_button2);
        cmdRight.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(rightClickListener!=null){
					rightClickListener.onClick(v);
				}
				
				myDialog.dismiss();
			}
		});
	}
	
	public void showDialog(){
		myDialog.show();
	}
	
	public String getKeyCodeString(){
		return txtCheckCode.getText().toString().trim();
	}
	
	public void txtCheckCodeSetHint(String hint){
		txtCheckCode.setHint(hint);
	}
	
	public void txtCheckCodeSetInputType(int type){
		txtCheckCode.setInputType(type);
	}
	
	public void hideDialog(){
		myDialog.dismiss();
	}
	
	public boolean isShowDialog(){
		return myDialog.isShowing();
	}
}
